package cn.duxiaod.demo.keyword;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * java关键字测试
 */
public class JavaKeyWordTest {

    @Test
    public void finalTest(){
        final int a = 1;
        //a = 2; //编译错误：Cannot assign a value to final variable 'a'
        final List<String> strings = new ArrayList<String>(){{
            add("abc");
            add("def");
            add("asd");
        }};
        strings.add("def");
        strings.forEach(System.out::println);
        System.out.println("-------------------");
    }

    /**
     * static 关键字主要有以下四种使用场景
     * 修饰成员变量和成员方法
     * 静态代码块
     * 修饰类(只能修饰内部类)
     * 静态导包(用来导入类中的静态资源，1.5之后的新特性)
     */
    @Test
    public void staticTest(){
        StaticDemo staticDemo1 = new StaticDemo("lisi");
        StaticDemo staticDemo2 = new StaticDemo("wangwu");
        StaticDemo staticDemo3 = new StaticDemo("zhaoliu");
        staticDemo1.age = 33;
        System.out.println(staticDemo1 + " " + staticDemo2 + " " + staticDemo3);
        staticDemo1.sayHi();
    }
}
